import { defineStore } from 'pinia'
import { getBaseVenue } from '../../api/ven'
import useUserStore from './user'

const useVenStore = defineStore('ven',
  {
    state: () => ({
      venueInfo: {},
      businessPeriod: ['00:00', '23:30'],
      projectList: []
    }),
    actions: {
      setBusinessPeriod(businessPeriod) {
        this.businessPeriod = businessPeriod
      },
      getBaseVenInfo() {
        return getBaseVenue(useUserStore().user.venueId).then((res) => {
          const data = res.data
          if (data.businessPeriod) {
            data.businessStart = data.businessPeriod.split(',')[0]
            data.businessEnd = data.businessPeriod.split(',')[1]
          }
          this.venueInfo = data
          this.setBusinessPeriod([data.businessStart, data.businessEnd])
        })
      },
      setProjectList(list) {
        this.projectList = list
      }
    }
  })

export default useVenStore
